/*!
 * Pomelo -- consoleModule sceneInfo
 * Copyright(c) 2012 fantasyni <fantasyni@163.com>
 * MIT Licensed
 */
var consts = require('../consts/consts');
var logger = require('log4js').getLogger(consts.LOG.GAME);
var utils = require('../util/utils');

module.exports = function(opts) {
    return new Module(opts);
};

module.exports.moduleId = 'lobbyInfo';

var Module = function(opts) {
    opts = opts || {};
    this.type = opts.type || 'pull';
    this.interval = opts.interval || 5;
};

Module.prototype.monitorHandler = function(agent, msg, cb) {
    //collect data
    var serverId = agent.id;
    // var area = require('../domain/area/area');
    // var data = area.getAllPlayers();
    // agent.notify(module.exports.moduleId, {serverId: serverId, body: data});
};

Module.prototype.masterHandler = function(agent, msg, cb) {
    if(!msg) {
        // pull interval callback
        var list = agent.typeMap['game'];
        if(!list || list.length === 0) {
            return;
        }
        agent.notifyByType('game', module.exports.moduleId);
        return;
    }

    var data = agent.get(module.exports.moduleId);
    if(!data) {
        data = {};
        agent.set(module.exports.moduleId, data);
    }
    data[msg.serverId] = msg.body;
};

Module.prototype.clientHandler = function(agent, msg, cb) {
    utils.invokeCallback(cb, null, agent.get(module.exports.moduleId));
};
